import java.util.*;
public class Test{
    public static void main(String[] args){

        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = in.nextInt();
        }

        int[] tmp = getMaxAndMin(arr);

        int maxVal = tmp[0];
        int minVal = tmp[1];

        int maxIndex = getIndex(arr, maxVal);
        int minIndex = getIndex(arr, minVal);

        int right = 0;
        int left = 0;

        boolean judge = false;
        for(int i = minIndex; i < n; i++){
            if(arr[i]*2 <= maxVal){
                right = i;
                judge = true;
            }
        }
        for(int i = minIndex; i >= 0; i--){
            if(arr[i]*2 <= maxVal){
                left = i;
                judge = true;
            }
        }

        if(judge == false){
            arr[minIndex] *= 2;
        }
        else{
            for(int i = left; i <= right; i++){
                arr[i]*=2;
            }
        }

        tmp = getMaxAndMin(arr);
        maxVal = tmp[0];
        minVal = tmp[1];
        System.out.println(maxVal - minVal);
    }

    //获取指定元素的下标
    public static int getIndex(int[] arr, int val){
        int len = arr.length;
        for(int i = 0; i < len; i++){
            if(val == arr[i])
                return i;
        }
        return -1;
    }
    //找出数组中的最大最小值
    public static int[] getMaxAndMin(int[] arr){
        int n = arr.length;
        int maxVal = arr[0];
        int minVal = arr[0];
        for(int i = 0; i < n; i++){
            if(maxVal < arr[i])
                maxVal = arr[i];
            if(minVal > arr[i])
                minVal = arr[i];
        }
        int[] tmp = new int[2];
        tmp[0] = maxVal;
        tmp[1] = minVal;
        return tmp;
    }
}